package com.sx.manage.service.consumer;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.sx.manage.biz.consumer.IMConsumerEditInfoBiz;
import com.sx.manage.biz.consumer.bank.IMConsumerBankMapBiz;
import com.sx.manage.biz.consumer.info.IMNetworkPersonConsumerBiz;
import com.sx.manage.biz.consumer.relation.IMConsumerDataRelationBiz;
import com.sx.manage.service.bank.IMBaseConsumerBankMapService;
import com.sx.manage.service.consumer.info.IMConsumerOperationInfoService;
import com.sx.manage.service.sys.IMBaseSystemConfigInfoService;
import com.sx.manage.service.sys.IMSystemConfigInfoService;
import com.sx.manage.servlet.ViewAndModel;
import com.sx.model.constants.MSystemConstants;
import com.sx.model.constants.type.consumer.MConsumerDataRelationType;
import com.sx.model.manage.mybatis.form.bank.MConsumerBankMapForm;
import com.sx.model.manage.mybatis.form.consumer.MPersonalConsumerNetworkForm;
import com.sx.model.manage.mybatis.form.sys.MSystemConfigInfoForm;
import com.sx.model.manage.mybatis.vo.consumer.MConsumerBankMapVO;
import com.sx.model.manage.mybatis.vo.consumer.MConsumerDataRelationVO;
import com.sx.model.manage.mybatis.vo.consumer.MPersonalConsumerVO;
import com.sx.model.manage.mybatis.vo.result.ResultBooleanVO;
import com.sx.model.manage.mybatis.vo.result.ResultListVO;
import com.sx.model.manage.mybatis.vo.sys.MSysConfigVO;

/**
 * 个人用户信息
 * 
 * @author lenovo
 *
 */
@Service("consumerBankWebServiceImpl")
public class MConsumerBankWebServiceImpl {
	// 日志
	private Logger _log = LoggerFactory.getLogger(this.getClass());

	// 用户信息新接口
	@Resource(name = "mNetworkPersonConsumerBizImpl")
	public IMNetworkPersonConsumerBiz mNetworkPersonConsumerBizImpl;

	@Resource(name = "mConsumerEditInfoBizImpl")
	private IMConsumerEditInfoBiz mConsumerEditInfoBizImpl;
	// 系统参数配置
	@Resource(name = "systemConfigInfoServiceImpl")
	private IMSystemConfigInfoService systemConfigInfoServiceImpl;
	// 系统参数配置
	@Resource(name = "mBaseSystemConfigInfoServiceImpl")
	private IMBaseSystemConfigInfoService mBaseSystemConfigInfoServiceImpl;
	// 二期 用户各种状态查询
	@Resource(name = "consumerOperationInfoServiceImpl")
	private IMConsumerOperationInfoService consumerOperationInfoServiceImpl;
	// 用户银行关系
	@Resource(name = "mBaseConsumerBankMapServiceImpl")
	private IMBaseConsumerBankMapService mBaseConsumerBankMapServiceImpl;
	
	@Resource(name="mConsumerDataRelationBizImpl")
	private IMConsumerDataRelationBiz mConsumerDataRelationBizImpl;
	
	@Resource(name="mConsumerBankMapBizImpl")
	private IMConsumerBankMapBiz mConsumerBankMapBizImpl;


	public IMSystemConfigInfoService getSystemConfigInfoServiceImpl() {
		return systemConfigInfoServiceImpl;
	}

	public void setSystemConfigInfoServiceImpl(IMSystemConfigInfoService systemConfigInfoServiceImpl) {
		this.systemConfigInfoServiceImpl = systemConfigInfoServiceImpl;
	}

	public IMNetworkPersonConsumerBiz getmNetworkPersonConsumerBizImpl() {
		return mNetworkPersonConsumerBizImpl;
	}

	public void setmNetworkPersonConsumerBizImpl(IMNetworkPersonConsumerBiz mNetworkPersonConsumerBizImpl) {
		this.mNetworkPersonConsumerBizImpl = mNetworkPersonConsumerBizImpl;
	}

	public IMConsumerEditInfoBiz getmConsumerEditInfoBizImpl() {
		return mConsumerEditInfoBizImpl;
	}

	public void setmConsumerEditInfoBizImpl(IMConsumerEditInfoBiz mConsumerEditInfoBizImpl) {
		this.mConsumerEditInfoBizImpl = mConsumerEditInfoBizImpl;
	}

	public IMConsumerOperationInfoService getConsumerOperationInfoServiceImpl() {
		return consumerOperationInfoServiceImpl;
	}

	public void setConsumerOperationInfoServiceImpl(IMConsumerOperationInfoService consumerOperationInfoServiceImpl) {
		this.consumerOperationInfoServiceImpl = consumerOperationInfoServiceImpl;
	}

	public IMBaseConsumerBankMapService getmBaseConsumerBankMapServiceImpl() {
		return mBaseConsumerBankMapServiceImpl;
	}

	public void setmBaseConsumerBankMapServiceImpl(IMBaseConsumerBankMapService mBaseConsumerBankMapServiceImpl) {
		this.mBaseConsumerBankMapServiceImpl = mBaseConsumerBankMapServiceImpl;
	}
	
	public Logger get_log() {
		return _log;
	}

	public void set_log(Logger _log) {
		this._log = _log;
	}

	public IMBaseSystemConfigInfoService getmBaseSystemConfigInfoServiceImpl() {
		return mBaseSystemConfigInfoServiceImpl;
	}

	public void setmBaseSystemConfigInfoServiceImpl(IMBaseSystemConfigInfoService mBaseSystemConfigInfoServiceImpl) {
		this.mBaseSystemConfigInfoServiceImpl = mBaseSystemConfigInfoServiceImpl;
	}

	public IMConsumerDataRelationBiz getmConsumerDataRelationBizImpl() {
		return mConsumerDataRelationBizImpl;
	}

	public void setmConsumerDataRelationBizImpl(IMConsumerDataRelationBiz mConsumerDataRelationBizImpl) {
		this.mConsumerDataRelationBizImpl = mConsumerDataRelationBizImpl;
	}

	/**
	 * 跳转到添加界面
	 */
	public ViewAndModel toCardNumAdd(ViewAndModel model, Long consumer_id) {
		_log.debug("银行卡新增界面：consumer_id={}",consumer_id);

		MConsumerDataRelationVO relationVO = mConsumerDataRelationBizImpl.query_by_consumer_id_and_relation_type(consumer_id, 
				MConsumerDataRelationType.CONSUMER_PERSON_CHANNEL_TYPE ).getObjVo();
		MSystemConfigInfoForm form = new MSystemConfigInfoForm();
							  form.setConfig_type( MSystemConstants.OPEN_ACCOUNT_CHANNEL_TYPES );
		if( null != relationVO ){
			_log.debug("用户配置开户渠道，获取渠道列表consumer_id={}");
			 form.setConfig_value( relationVO.getRelation_string_num());
		}
		List<MSysConfigVO> type_list = mBaseSystemConfigInfoServiceImpl.querySystemConfigList(form).getData();
		
		 model.addObject("type_list", type_list);
		model.addObject("consumer_id", consumer_id); 
		return model;

	}
	/** 银行卡新增**/
	public ResultBooleanVO cardNumAdd(MConsumerBankMapForm bankMapForm ){
		return this.mConsumerBankMapBizImpl.bank_insert(bankMapForm);
	}
	/** 银行卡编辑**/
	public ResultBooleanVO cardNumEdit(MConsumerBankMapForm bankMapForm ){
		return this.mConsumerBankMapBizImpl.bank_edit(bankMapForm);
	}
	/**
	 * 跳转到编辑界面
	 */
	public ViewAndModel toCardNumEdit(ViewAndModel model, Long bank_map_id) {
		_log.debug("银行卡信息编辑界面：bank_map_id={}");
		MConsumerBankMapVO bankMapVO = this.mBaseConsumerBankMapServiceImpl.query_consumer_bank_map_by_id( bank_map_id ).getObjVo();
		model.addObject("bankMapVO", bankMapVO); 
		return model;
	}

	
	/** 删除银行卡信息**/
	public ResultBooleanVO deleteCardNumById(Long bank_map_id){
		return this.mConsumerBankMapBizImpl.delete_bank_by_id( bank_map_id );
	}
	/**下拉选择-入金账户-入金姓名*/
	public ResultListVO<MPersonalConsumerVO> queryConsumerBankForSelect(MPersonalConsumerNetworkForm form){
		return mNetworkPersonConsumerBizImpl.queryConsumerBankForSelect(form);
	}
}
